package com.gutai.admin.biz;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import com.gutai.admin.common.entity.dto.SelectListDto;

/**
 * 
 * 描述：
 * 
 * <pre>
 * HISTORY
 * ****************************************************************************
 *  ID    DATE            PERSON            REASON
 *  1     2019年5月1日         YC           Create
 * ****************************************************************************
 * </pre>
 * 
 * @author YC
 * @version 1.0
 */
@Service
public class OrderStatusHelper implements InitializingBean {

    private OrderStatusHelper() {}

    private static List<SelectListDto> orderStatusList = new ArrayList<>();


    @Override
    public void afterPropertiesSet() throws Exception {
        initStatusList();
    }

    private void initStatusList() {
        orderStatusList.add(new SelectListDto(101, "已取消"));
        orderStatusList.add(new SelectListDto(0, "待付款"));
        orderStatusList.add(new SelectListDto(201, "待发货"));
        orderStatusList.add(new SelectListDto(210, "待收货"));
        orderStatusList.add(new SelectListDto(211, "已完成"));
    }


    public static List<SelectListDto> getOrderStatusList() {
        return orderStatusList;
    }

    public static String getOrderStatusByCode(Integer code) {
        SelectListDto statusCode = orderStatusList.stream().filter(orderStatus -> code.equals(orderStatus.getId())).findFirst().orElse(null);
        if (statusCode!=null){
            return statusCode.getName();
        }
        return String.valueOf(code);
    }
    
    public static Integer getOrderStatusByName(String name) {
        SelectListDto statusCode = orderStatusList.stream().filter(orderStatus -> name.equals(orderStatus.getName())).findFirst().orElse(null);
        if (statusCode!=null){
            return statusCode.getId();
        }
        return null;
    }


}
